package com.ruoyi.yey.FastDfs;

import com.luhuiguo.fastdfs.service.FastFileStorageClient;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


/**
 * 参数配置 信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/upload")
public class UpLoadController extends BaseController
{
    @Resource
    private FastDfsServiceImpl fastDfsService;

    @Resource
    public FastFileStorageClient storageClient;

    /**
     * DFS测试
     */
//    @RequiresPermissions("system:config:list")
    @Log(title = "DFS测试", businessType = BusinessType.UPDATE)
    @PostMapping("/hutool")
    public Object list(MultipartFile file)
    {
        return fastDfsService.Upload(file);
    }

    @Log(title = "文件下载", businessType = BusinessType.EXPORT)
    @PostMapping("/download")
    public void export() throws IOException {
        byte[] group1s = storageClient.downloadFile("group1", "86501729/仅限自己用，禁止倒卖.png");
        OutputStream outputStream=new FileOutputStream(new File("C:\\Users\\Administrator\\Desktop\\123.png"));
        outputStream.write(group1s);
        outputStream.flush();
        outputStream.close();
    }

}
